package eSignDemo

import (
	"github.com/zeromicro/go-zero/rest/httpx"
	"gozero-demo/internal/logic/eSignDemo"
	"gozero-demo/internal/middleware"
	"gozero-demo/internal/svc"
	"gozero-demo/internal/types"
	"net/http"
)

// 通过模板创建合同文件
func CreateByTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.CreateByTemplateRequest
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		// 验证请求参数
		if err := middleware.ValidateRequest(&req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := eSignDemo.NewCreateByTemplateLogic(r.Context(), svcCtx)
		resp, err := l.CreateByTemplate(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
